﻿@model PortalWeb.Areas.Admin.Models.EditRoleViewModel

@{
    Layout = null;
    ViewBag.Title = "角色编辑";
}


@using (Ajax.BeginForm("Edit", "Role", new AjaxOptions
{
    InsertionMode = InsertionMode.Replace,
    HttpMethod = "POST",
    OnSuccess = "OnSuccess"
}, new { @class = "form-horizontal", role = "form" }))
{
    @Html.AntiForgeryToken()

    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h4 id="myModalLabel" class="modal-title">@ViewBag.Title</h4>
        </div>
        @Html.ValidationSummary(true, "", new {@class = "text-danger"})
        @Html.HiddenFor(model => model.Id)
        <div class="modal-body">
            <div class="form-group">
                @Html.LabelFor(model => model.Name, htmlAttributes: new {@class = "control-label col-md-2"})
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Name, new {htmlAttributes = new {@class = "form-control"}})
                    @Html.ValidationMessageFor(model => model.Name, "", new {@class = "text-danger"})
                </div>
            </div>

            <div class="form-group">
                @Html.LabelFor(model => model.Describe, htmlAttributes: new {@class = "control-label col-md-2"})
                <div class="col-md-10">
                    @Html.EditorFor(model => model.Describe, new {htmlAttributes = new {@class = "form-control"}})
                    @Html.ValidationMessageFor(model => model.Describe, "", new {@class = "text-danger"})
                </div>
            </div>
            <div class="form-group">
                @Html.LabelFor(model => model.Functions, htmlAttributes: new { @class = "control-label col-md-2" })
                @Html.HiddenFor(model => model.Functions)
                <div class="col-md-10">
                    <div id="FunctionTree"></div>
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <input type="submit" value="保存" class="btn btn-default"/>
            <button class="btn  btn-default" data-dismiss="modal" aria-hidden="true">取消</button>
        </div>
    </div>
}


    <script>
        $.ajax({
            type: "POST",
            url: "@Url.Action("FunctionTree","Authorize")",
            dateType: "json",
            data: {},
            contentType: "application/x-www-form-urlencoded; charset=utf-8",
            success: function (response) {
                if (response.status)
                    $('#FunctionTree').treeview({
                        data: response.data,
                        levels: 5,
                        showIcon: true,
                        showCheckbox: true,
                        onNodeChecked: function (event, data) {
                            // Your logic goes here
                            $("#Functions").val( data.pid);
                        },
                        onNodeUnchecked: function (event, data) {
                            // Your logic goes here
                            $("#Functions").val(data.pid);

                        }
                    })
            }
        });
    </script>

